package org.xtense.tests;

//import java.util.List;

import java.util.List;

import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Node;

public class XpathTest {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		//		 SAXReader reader = new SAXReader();
	        try {
// Document doc = reader.read("test.xml");
	        	Document doc = DocumentHelper
					.parseText("<tempRoot><book year=\"2000\"><title>Database System Concept</title><price>26.50</price><author id=\"001\"><name>Kaily Jone</name><email>kjone@research.bell-labs.com</email></author><author id=\"102\"><name>Silen Smith</name></author></book><book year=\"2001\"><title>Introduction to XML</title><price>18.80</price><author id=\"103\"><name>Kaily Jone</name></author><book>what are you ** doing?</book></book><book>aaaaaa</book></tempRoot>");
	            System.out.println(doc.asXML());
			// Element root = doc.getRootElement();
	           
	            
//	            Node t = root.selectSingleNode("//book");
//	            System.out.println(t.asXML());
//	            List list = t.selectNodes("//title");
	            
//	            List list = root.selectNodes("//title[@id='789']/ancestor::*");
	            
//	            List list = root.selectNodes("//book/descendant::*");
	            
//	            List list = root.selectNodes("//title/parent::*");
	            

			// Node node = root.selectSingleNode("//book");
			// System.out.println(node.asXML());
 List list = doc.selectNodes("//@year[='2000']");


			for (Object o : list) {

				Node e = (Node) o;
				System.out.println("--------Print the result node--------");
				System.out.println(e.asXML());

			}

			//	            System.out.println(root.selectSingleNode("//book/title").getPath());
//	            Node tx = root.selectSingleNode("//book/title");
//	            
//	            System.out.println(tx.getText());
	          
	        } catch (Exception e) {
	            e.printStackTrace();
	        }

	}

}
